<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html lang="zh-cn">
    <head>
        <title>Hiring-首页</title>
        <%@ include file="/WEB-INF/view/common/import.jsp"%>
        <style>
        	.select {
        		height : 34px;
        		border: 1px solid #ccc;
        	}
        	.search-input {
        		width: 50% !important;
        		margin: 20px auto;
        	}
        </style>
    </head>
    <body>
    	<div class="container">
    		<a href="<%=request.getContextPath()%>/TalentServlet?command=toLoginUI">求职者登录</a>&nbsp;&nbsp;<a href="">求职者注册</a>&nbsp;&nbsp;<a href="<%=request.getContextPath()%>/CompanyServlet?command=toLoginUI">企业登录</a>&nbsp;&nbsp;<a href="">企业注册</a>&nbsp;&nbsp;<a href="<%=request.getContextPath()%>/CommonServlet?command=listAreaInfo">城市三级级联</a>
    		<hr>
    		
	      	<c:if test="${empty pageModel.list}">
	      		<div class="alert alert-warning text-center" role="alert">没有相关数据！</div>
	      	</c:if>
	      	<c:if test="${! empty pageModel.list}">
			    <form action="<%=request.getContextPath()%>/PositionServlet?command=listPosition" method="POST" id="searchForm">
				    <div class="input-group search-input">
				       <input type="text" class="form-control" placeholder="职位名/公司名" name="searchText" value="${searchText }">
				       <span class="input-group-btn">
				         <button class="btn btn-primary" type="submit">搜索</button>
				       </span>
				    </div>
			    </form>
			    
		      	<c:forEach items="${pageModel.list }" var="position" varStatus="vs">
		    		<div class="panel panel-primary">
					  <div class="panel-heading">
					    <h3 class="panel-title"><strong><kbd>${vs.count + (pageModel.pageNo - 1) * pageModel.pageSize}</kbd> &nbsp; ${position.company$name }</strong>&nbsp;&nbsp;"${position.company$slogan }"</h3>
					  </div>
					  <div class="panel-body">
					       <a href="">${position.name }</a> &nbsp;&nbsp; ￥${position.salary1 }~${position.salary2 } &nbsp;&nbsp; ${position.company$address } &nbsp;&nbsp; <fmt:formatDate value="${position.releaseTime }" pattern="yyyy-MM-dd HH:mm:ss"/>
					  </div>
					</div>
		        </c:forEach>
		        <div class="pull-right">
		        	<button type="button" class="btn btn-default" onclick="go(${pageModel.first})" <c:if test="${pageModel.pageNo == pageModel.first }">disabled="disabled"</c:if>>首页</button>
		        	<button type="button" class="btn btn-default" onclick="go(${pageModel.pre})" <c:if test="${pageModel.pageNo == pageModel.first }">disabled="disabled"</c:if>>上一页</button>
		        	<select onchange="go(this.value)" class="select">
		        		<script>
		        			var totalPage = '${pageModel.totalPage }';
		        			var pageNo = '${pageModel.pageNo}'
		        			for (var i = 1; i <= totalPage; i++) {
		        				if (i == pageNo) {
		        				   document.write('<option value="'+ i +'" selected>第' + i +'页</option>');
		        				} else {
		        				   document.write('<option value="'+ i +'">第' + i +'页</option>');	
		        				}
		        			}
		        		</script>
		        	</select>
		        	<button type="button" class="btn btn-default" onclick="go(${pageModel.next})" <c:if test="${pageModel.pageNo == pageModel.last }">disabled="disabled"</c:if>>下一页</button>
		        	<button type="button" class="btn btn-default" onclick="go(${pageModel.last})" <c:if test="${pageModel.pageNo == pageModel.last }">disabled="disabled"</c:if>>尾页</button>
		        	&nbsp;&nbsp;&nbsp;&nbsp;
		        	当前第${pageModel.pageNo }页，
		        	显示${(pageModel.pageNo - 1) * pageModel.pageSize + 1}到第${(pageModel.pageNo - 1) * pageModel.pageSize + pageModel.pageSize}，共${pageModel.totalPage }页
		        </div>
		     </c:if>
    	</div>
    	
    	<script>
    		/**
    		 * 指定跳转到第几页
    		 */
    		var searchForm = $('#searchForm')[0];
    		function go(pageNo) {
    			searchForm.action = '<%=request.getContextPath()%>/PositionServlet?command=listPosition&pageNo=' + pageNo;
    			searchForm.submit();
    		}
    	</script>
    </body>
</html>
